var _localObject =  window.wx ? wx : cc.sys.localStorage;
function _getLocalItem( key ){
    let v = window.wx ? window.wx.getStorageSync(key) : cc.sys.localStorage.getItem(key);
    if(!window.wx){
        try{
            v = JSON.parse(v);
        }catch(err){
            v = v;
        }
    }
    // $G.say("_getLocalItem:"+key);
    // $G.say(v);
    return v;
}
function _setLocalItem( key , v ){
    if(window.wx && window.wx.setStorageSync){
        //let tmp = window.wx.getStorageSync( key );
        try{
            // $G.say("_setLocalItem:"+ key);
            // $G.say(v);
            window.wx.setStorageSync( key , v);
        }catch(err){
            // $G.say("_setLocalItem:"+ key+"_tmp");
            setTimeout(() => {
                try{
                    window.wx.setStorageSync( key , v);
                }catch(omg){
                    $G.say("omg set err!");
                }
            }, 10);
            //window.wx.setStorageSync( key , v)
            // $G.say("save key err : "+ key);
            // $G.say(err);
        }
    }else if(cc.sys && cc.sys.localStorage){
        cc.sys.localStorage.setItem(key , JSON.stringify(v) )
    }
    return v;
}


module.exports = {
    get : _getLocalItem ,
    set : _setLocalItem
}